package com.stylefeng.guns.modular.system.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.system.model.Gdprice;
import com.stylefeng.guns.modular.system.service.IGdpriceService;

/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2018-05-19 10:39:41
 */
@Controller
@RequestMapping("/gdprice")
public class GdpriceController extends BaseController {

    private String PREFIX = "/system/gdprice/";

    @Autowired
    private IGdpriceService gdpriceService;

    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "gdprice.html";
    }

    /**
     * 跳转到添加
     */
    @RequestMapping("/gdprice_add")
    public String gdpriceAdd() {
        return PREFIX + "gdprice_add.html";
    }

    /**
     * 跳转到修改
     */
    @RequestMapping("/gdprice_update/{gdpriceId}")
    public String gdpriceUpdate(@PathVariable Integer gdpriceId, Model model) {
        Gdprice gdprice = gdpriceService.selectById(gdpriceId);
        model.addAttribute("item",gdprice);
        LogObjectHolder.me().set(gdprice);
        return PREFIX + "gdprice_edit.html";
    }

    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return gdpriceService.selectList(null);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Gdprice gdprice) {
        gdpriceService.insert(gdprice);
        return SUCCESS_TIP;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer gdpriceId) {
        gdpriceService.deleteById(gdpriceId);
        return SUCCESS_TIP;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Gdprice gdprice) {
        gdpriceService.updateById(gdprice);
        return SUCCESS_TIP;
    }

    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{gdpriceId}")
    @ResponseBody
    public Object detail(@PathVariable("gdpriceId") Integer gdpriceId) {
        return gdpriceService.selectById(gdpriceId);
    }
}
